<template>
	<view class="ca-container">
		<view class="list" v-if="dataPageList.length>0">
			<view class="list-item" v-for="(item,index) in dataPageList" @click="bindItemClick" :data-id="item.id">
				<view class="ca-txt-ellipsis1">{{item.remark}}</view>
				<image src="../../static/icon/icon_action_more.png" mode="aspectFit"></image>
			</view>
		</view>
		<listEmpty v-else></listEmpty>
	</view>
</template>

<script>
	const APP = getApp();
	
	export default {
		data() {
			return {
				//分页数据
				dataPageList: [],
				dataPageNum: 0,
			}
		},
		methods: {
			bindItemClick(e) {
				let dataset = e.currentTarget.dataset;
				// uni.navigateTo({
				// 	url:'/pages/detail?tid='+dataset.id
				// });
				APP._apptool().showToastInfo('编号：'+dataset.id);
			},
			loadPageData: function() {
				let _this = this;
				_this.loadPageList(null);
			},
			loadPageList: function(completedcallback) {
				let _this = this;
				
				let params = {
					caPageIndex: _this.dataPageNum + 1,
				};
				
				APP._post('/miniprogram/NavLayout/list',  params, null, function(res) {
					//执行成功
					if (res.caCode === APP._appconfig().fwcode.successed) {
						if (res.caData.caPageList.length > 0) {
							_this.dataPageNum = parseInt(res.caData.caPageIndex);
							_this.dataPageList = _this.dataPageList.concat(res.caData.caPageList);
						} else {
							_this.dataPageNum = -1;
						}
					} else {
						APP._apptool().showToastInfo(res.caMsg);
					}
				}, function(res) {
					//执行失败
					APP._applog().error(res);
				}, function(res) {
					//执行完成
					completedcallback && completedcallback();
				});
			},
			refreshPage: function(){
				this.dataPageList = [];
				this.dataPageNum = 0;
				this.loadPageList(function() {
					uni.stopPullDownRefresh();
				});
			}
		},
		//生命周期
		onLoad(option) {
			// if(option.param){
			// 	let options = APP._apptool().decodeJsonStr(option.param);
			// }
			this.loadPageData();
		},
		onShow() {

		},
		onReady() {

		},		
		onHide() {

		},
		onUnload() {

		},
		onPullDownRefresh() {
			this.refreshPage();
		},
		onReachBottom() {
			let _this = this;
		
			if (this.dataPageNum !== -1) {
				// 显示加载图标
				uni.showLoading({
					title: '加载中...',
				})
				this.loadPageList(function() {
					uni.hideLoading();
				});
			} else {
				APP._apptool().showToastInfo('已经是最后一页了');
			}
		},
		onBackPress(options) {

		},
		onPageScroll(e) {

		}
	}
</script>

<style lang="scss">
	.list{
		width: 100%; height:auto;
		display: flex; display: -webkit-flex; flex-direction: column; align-items: center;
		.list-item{
			width: 95%; height: auto; padding: 20rpx 0rpx;
			display: flex; display: -webkit-flex; flex-direction: row; align-items: center; justify-content: space-between;
			border-bottom: 1rpx solid #DDDDDD;
			view{
				flex: 1;
			}
			image{
				width: 40rpx; height: 40rpx;
			}
		}
		.list-item:active{
			background-color: #EFEFEF;
		}
	}
</style>

